Skip to content

Conversation

@klausler
Copy link
Contributor

@klausler klausler commented Mar 5, 2025

The FROM= and TO= arguments in a reference to the MOVE_ALLOC intrinsic subroutine must have the same corank.

The FROM= and TO= arguments in a reference to the MOVE_ALLOC intrinsic
subroutine must have the same corank.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

The FROM= and TO= arguments in a reference to the MOVE_ALLOC intrinsic subroutine must have the same corank.


Full diff: https://github.com/llvm/llvm-project/pull/129944.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+7)
  • (modified) flang/test/Semantics/move_alloc.f90 (+4-1)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index ecc1e3d27e3bf..e3c716fce4ebb 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1840,6 +1840,13 @@ static void CheckMove_Alloc(evaluate::ActualArguments &arguments,
   if (arguments.size() >= 2) {
     evaluate::CheckForCoindexedObject(
         messages, arguments[1], "move_alloc", "to");
+    int fromCR{GetCorank(arguments[0])};
+    int toCR{GetCorank(arguments[1])};
+    if (fromCR != toCR) {
+      messages.Say(*arguments[0]->sourceLocation(),
+          "FROM= argument to MOVE_ALLOC has corank %d, but TO= argument has corank %d"_err_en_US,
+          fromCR, toCR);
+    }
   }
   if (arguments.size() >= 3) {
     evaluate::CheckForCoindexedObject(
diff --git a/flang/test/Semantics/move_alloc.f90 b/flang/test/Semantics/move_alloc.f90
index 3303a002039bb..73db594129eab 100644
--- a/flang/test/Semantics/move_alloc.f90
+++ b/flang/test/Semantics/move_alloc.f90
@@ -1,7 +1,7 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
 ! Check for semantic errors in move_alloc() subroutine calls
 program main
-  integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:)
+  integer, allocatable :: a(:)[:], b(:)[:], f(:), g(:), h(:)[:,:]
   type alloc_component
     integer, allocatable :: a(:)
   end type
@@ -73,4 +73,7 @@ program main
   !ERROR: Argument #2 to MOVE_ALLOC must be allocatable
   call move_alloc(f, g(::2))
 
+  !ERROR: FROM= argument to MOVE_ALLOC has corank 1, but TO= argument has corank 2
+  call move_alloc(a, h)
+
 end program main

@klausler klausler merged commit f6fc29d into llvm:main Mar 10, 2025
14 checks passed
@klausler klausler deleted the fix137 branch March 10, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants